package com.example.flutter_demo2.aty

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import androidx.fragment.app.Fragment
import com.example.flutter_demo2.R

interface OnBack2flutter {
    fun onBack2flutter()
}

class WebViewFragment(onBack2flutter: OnBack2flutter) : Fragment() {

    private var mOnBack2flutter: OnBack2flutter? = null

    init {
        mOnBack2flutter = onBack2flutter
    }

    // or cast
//    override fun onAttach(context: Context) {
//        super.onAttach(context)
//        mOnBack2flutter = context as? OnBack2flutter
//    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.fragment_web_view, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        val btn = view.findViewById<Button>(R.id.btn_back)
        btn?.setOnClickListener {
            mOnBack2flutter?.onBack2flutter()
        }
    }

}